// Package logger 直接调用loggger来输出日志
package logger

import (
	"context"
	"fmt"
	"gitee.com/dingyangzhuang/dingutils/dlog"
	"runtime"
)

// Debug logs at [LevelDebug].
func Debug(msg string, args ...any) {
	_, file, line, ok := runtime.Caller(1)
	if !ok {
		fmt.Println("runtime.Caller() failed")
	}
	dlog.GetLogger().Debug(msg, args, "file", file, "line", line)

}

// DebugContext logs at [LevelDebug] with the given context.
func DebugContext(ctx context.Context, msg string, args ...any) {
	_, file, line, ok := runtime.Caller(1)
	if !ok {
		fmt.Println("runtime.Caller() failed")
	}
	dlog.GetLogger().DebugContext(ctx, msg, args, "file", file, "line", line)
}

// Info logs at [LevelInfo].
func Info(msg string, args ...any) {
	_, file, line, ok := runtime.Caller(1)
	if !ok {
		fmt.Println("runtime.Caller() failed")
	}
	dlog.GetLogger().Info(msg, args, "file", file, "line", line)
}

// InfoContext logs at [LevelInfo] with the given context.
func InfoContext(ctx context.Context, msg string, args ...any) {
	_, file, line, ok := runtime.Caller(1)
	if !ok {
		fmt.Println("runtime.Caller() failed")
	}
	dlog.GetLogger().InfoContext(ctx, msg, args, "file", file, "line", line)
}

// Warn logs at [LevelWarn].
func Warn(msg string, args ...any) {
	_, file, line, ok := runtime.Caller(1)
	if !ok {
		fmt.Println("runtime.Caller() failed")
	}
	dlog.GetLogger().Warn(msg, args, "file", file, "line", line)
}

// WarnContext logs at [LevelWarn] with the given context.
func WarnContext(ctx context.Context, msg string, args ...any) {
	_, file, line, ok := runtime.Caller(1)
	if !ok {
		fmt.Println("runtime.Caller() failed")
	}
	dlog.GetLogger().WarnContext(ctx, msg, args, "file", file, "line", line)
}

// Error logs at [LevelError].
func Error(msg string, args ...any) {
	_, file, line, ok := runtime.Caller(1)
	if !ok {
		fmt.Println("runtime.Caller() failed")
	}
	dlog.GetLogger().Error(msg, args, "file", file, "line", line)
}

// ErrorContext logs at [LevelError] with the given context.
func ErrorContext(ctx context.Context, msg string, args ...any) {
	_, file, line, ok := runtime.Caller(1)
	if !ok {
		fmt.Println("runtime.Caller() failed")
	}
	dlog.GetLogger().ErrorContext(ctx, msg, args, "file", file, "line", line)
}
